//
//  GuideMallHeaderView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/14.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "GuideMallHeaderView.h"

#import "MainPageHeaderModel.h"

#import "ShopHeaderBannerView.h"

@interface GuideMallHeaderView()

@property (nonatomic,strong) ShopHeaderBannerView *bannerView;

@property (nonatomic,strong) UIImageView *bannerMengbanV;

@end

@implementation GuideMallHeaderView

#pragma mark - setter
- (void)setBannerSourceArr:(NSMutableArray *)bannerSourceArr{
    _bannerSourceArr = bannerSourceArr;
    self.bannerView.sourceArr = _bannerSourceArr;
    if (_bannerSourceArr.count <= 0) {
        self.bannerView.hidden = YES;
        self.bannerMengbanV.frame = self.bannerView.frame;
        [self addSubview:self.bannerMengbanV];
    }else{
        self.bannerView.hidden = NO;
        self.bannerMengbanV.hidden = YES;
    }
}
//轮播图蒙版
- (UIImageView *)bannerMengbanV{
    if (!_bannerMengbanV) {
        _bannerMengbanV = [[UIImageView alloc] initWithImage:LoadImage(@"首页_banner")];
    }
    return _bannerMengbanV;
}

-(id)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth*0.4)];
    imgV.image = LoadImage(@"首页_顶部背景");
    [self addSubview:imgV];
    
    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(70, kHeight_StatusBar + 10, ScreenWidth-70-60, 30)];
    tf.clipsToBounds = YES;
    tf.layer.cornerRadius = 15;
    tf.backgroundColor = RGBA(255, 255, 255, 0.8f);
    tf.placeholder = @"  请输入搜索内容";
    tf.leftView = [GuideMallHeaderView leftView];
    tf.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:tf];
    
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(ScreenWidth-54, tf.top, 30, 30);
    [menuBtn setImage:LoadImage(@"首页_消息") forState:normal];
    [menuBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    [menuBtn addTarget:self action:@selector(showMenuClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:menuBtn];
    
    self.bannerView = [[ShopHeaderBannerView alloc] initWithFrame:CGRectMake(10, tf.bottom+15, ScreenWidth-20, (ScreenWidth-20)*0.38)];
    self.bannerView.sourceArr = self.bannerSourceArr;
    [self addSubview:self.bannerView];
    self.height = self.bannerView.bottom+25;
    WEAKSELF(self);
    [self.bannerView setTouchBlock:^(NSInteger index) {
        if (weakSelf.bannerTouchBlock) {
            weakSelf.bannerTouchBlock(index);
        }
    }];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.updateHeightBlock) {
            self.updateHeightBlock(self.height);
        }
    });
}
+(UIView *)leftView{
    float tfWidth = (ScreenWidth-70-60);
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tfWidth/2-50, 30)];
    UIImageView *searchImgV = [[UIImageView alloc]initWithFrame:CGRectMake(view.width-15, 8, 15, 15)];
    searchImgV.image = LoadImage(@"首页_搜索");
    [view addSubview:searchImgV];
    return view;
}

//菜单
-(void)showMenuClick{
    
}





@end





